from django.conf.urls import url

from .views import *


urlpatterns = [
    url(r"^heros/$", HerosView.as_view()),
    url(r"^hero/(?P<pk>\d+)/$", HeroView.as_view()),
    # url(r"heros", HeroViewSet.as_view({'get': 'list'})),
    # url(r"hero/(?P<pk>\d+)/$", HeroViewSet.as_view({'get': 'retrieve'})),
]


"""
url(r"heros", HeroViewSet.as_view({'get': 'list'})),
url(r"hero/(?P<pk>\d+)/$", HeroViewSet.as_view({'get': 'retrieve'})),
此两个路由可合并成一个路由, 如下:
"""
from rest_framework.routers import SimpleRouter, DefaultRouter

# SimpleRouter与DefaultRouter区别:是否提供默认页面(SimpleRouter与DefaultRouter区别提供默认的API根视图)
# 推荐DefaultRouter

# 创建路由对象
router = DefaultRouter()
# 注册生成路由规则
router.register('heros', HeroViewSet)
# 将路由规则加入列表中
urlpatterns += router.urls
